import java.io.*;

public class FileHandler {
	private File file;
	
	public FileHandler(String filename) {
		file = new File(filename);
	}
	
	public FileHandler() {
		
	}
		
	public File getDirectoryFileObject() throws Exception {
		if(!file.isDirectory()) {
			throw new Exception(file.getAbsolutePath() + " er ikke en mappe.");
		}
		else if(!file.exists()) {
			throw new Exception(file.getAbsolutePath() + " Mappen finnes ikke.");
		}
		return file;
	}
	
	public String getFirstLinePackingSlip() throws IOException {
		FileReader fr = new FileReader(file);
		LineNumberReader ln = new LineNumberReader(fr);
		String s = "Feil";
		while (ln.getLineNumber() == 0){ 
			s = ln.readLine();
		}
		fr.close();
		return s;
	}
	
	public File getFileObject() throws Exception {
		if(file.isDirectory()) {
			throw new Exception("Filen er en mappe.");
		}
		else if(!file.exists()) {
			throw new Exception("Filen finnes ikke.");
		}
		return file;
	}
}